const http = require('http')
const fs = require('fs')
http.createServer((req, res) => {
    const {url, method} = req
    if(url === '/' && method === 'GET'){
        fs.readFile('./indexa.html', (err, data) => {
            if(err){
                res.writeHead(500, {
                    'Content-Type': 'text/plain;charset=utf8'
                })
                return res.end('500 服务器挂了')
            }else{
                res.statusCode = 200
                res.setHeader('Content-Type','text/html;charset=utf-8')
                res.end(data)
            }
        })
    }
    else{
        res.statusCode = 400
        res.setHeader('Content-Type', 'text/plain;charset=utf8');
        res.end('400 没这货')
    }
})
.listen(3000, () => {
    console.log('running server at 3000.....')
})